#ifndef __CHSC6X_H
#define __CHSC6X_H

#include <stdint.h>
#include <stdbool.h>
#ifdef LV_LVGL_H_INCLUDE_SIMPLE
#include "lvgl.h"
#else
#include "lvgl/lvgl.h"
#endif

#ifdef __cplusplus
extern "C" {
#endif

#define CHSC6X_I2C_SLAVE_ADDR       0x5C
#define I2C_MASTER_TIMEOUT_MS       1000



#define CHSC6X_I2C_ID      (CHSC6X_I2C_SLAVE_ADDR)
#define CHSC6X_MAX_POINTS_NUM     (1)
#define CHSC6X_RES_MAX_X	(370)
#define CHSC6X_RES_MAX_Y	(370)

/*MACRO SWITCH for driver update TP FW */
#define CHSC6X_AUTO_UPGRADE           0

/*MACRO SWITCH for multi TP_VENDOR Compatible update TP FW */
#define CHSC6X_MUL_VENDOR_UPGRADE     (0)

#define MAX_IIC_WR_LEN          (8)
#define MAX_IIC_RD_LEN          (16)

#define TXRX_ADDR       (0x9000)
#define CMD_ADDR        (0x9f00)
#define RSP_ADDR        (0x9f40)

#define EPERM           (1)
#define DIRECTLY_MODE   (0x0)
#define DEDICATE_MODE   (0x1)
#define LEN_CMD_CHK_TX  (10)
#define LEN_CMD_PKG_TX  (16)
#define LEN_RSP_CHK_RX  (8)
#define MAX_BULK_SIZE   (1024)

struct ts_fw_infos {
    unsigned short chsc6x_cfg_version;  //customer read 
    unsigned short chsc6x_boot_version; //customer read 
    unsigned short chsc6x_vendor_id;    //customer read 
    unsigned short chsc6x_project_id;   //customer read 
    unsigned short chsc6x_chip_id;      //customer read 
    unsigned short chsc6x_chip_type;    //customer read 
    unsigned short chsc6x_rpt_lcd_x;    //customer read must after chsc6x_get_chip_info
    unsigned short chsc6x_rpt_lcd_y;    //customer read must after chsc6x_get_chip_info
    unsigned short chsc6x_max_pt_num;   //customer read must after chsc6x_get_chip_info
};

struct ts_event {
    unsigned short x; /*x coordinate */
    unsigned short y; /*y coordinate */
    int flag; /* touch event flag: 0 -- down; 1-- up; 2 -- contact */
    int id;   /*touch ID */
};

struct chsc6x_updfile_header {
    unsigned int sig;
    unsigned int resv;
    unsigned int n_cfg;
    unsigned int n_match;
    unsigned int len_cfg;
    unsigned int len_boot;
};

typedef struct _test_cmd_wr {
    /* offset 0; */
    unsigned char id;    /* cmd_id; */
    unsigned char idv;    /* inverse of cmd_id */
    unsigned short d0;    /* data 0 */
    unsigned short d1;    /* data 1 */
    unsigned short d2;    /* data 2 */
    /* offset 8; */
    unsigned char resv;    /* offset 8 */
    unsigned char tag;    /* offset 9 */
    unsigned short chk;    /* 16 bit checksum */
    unsigned short s2Pad0;    /*  */
    unsigned short s2Pad1;    /*  */
} ctp_tst_wr_t;

typedef struct _test_cmd_rd {
    /* offset 0; */
    unsigned char id;    /* cmd_id; */
    unsigned char cc;    /* complete code */
    unsigned short d0;    /* data 0 */
    unsigned short sn;    /* session number */
    unsigned short chk;    /* 16 bit checksum */
} ctp_tst_rd_t;

void chsc6x_init(uint16_t dev_addr);
bool chsc6x_read(lv_indev_drv_t *drv, lv_indev_data_t *data);
void chsc6x_get_dot(void);


#ifdef __cplusplus
}
#endif
#endif 
